package com.zerui.manager.app.device;

import com.zerui.cola.dto.PageResponse;
import com.zerui.cola.dto.Response;
import com.zerui.cola.dto.SingleResponse;
import com.zerui.devicemanager.provider.ArchitectureDubboService;
import com.zerui.devicemanager.provider.dto.PositionNodeDTO;
import com.zerui.devicemanager.provider.dto.SummaryDTO;
import com.zerui.manager.app.device.executer.*;
import com.zerui.manager.web.DeviceService;
import com.zerui.manager.web.cmd.*;
import com.zerui.manager.web.vo.DevicePageVO;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.ParseException;
import java.util.List;

/**
 * @Author wh
 * @create_time 2023-08-23 11:08
 */
@Service
public class DeviceServiceImpl implements DeviceService {

	@DubboReference
	private ArchitectureDubboService architectureDubboService;
	@Resource
	private DeviceQryCmdExe deviceQryCmdExe;
	@Resource
	private DeviceSummaryCmdExe deviceSummaryCmdExe;
	@Resource
	private DeviceAddCmdExe deviceAddCmdExe;
	@Resource
	private DeviceUpdateCmdExe deviceUpdateCmdExe;
	@Resource
	private DeviceDelCmdExe deviceDelCmdExe;
	@Resource
	private DeviceOperateDoorCmdExe deviceOperateDoorCmdExe;
	@Resource
	private DeviceCurfewTimeCmdExe deviceCurfewTimeCmdExe;
	@Resource
	private DeviceCurfewOpenOrCloseCmdExe deviceCurfewOpenOrCloseCmdExe;

	@Override
	public SingleResponse<List<PositionNodeDTO>> getProductTree() {
		return architectureDubboService.getPositionTrees();
	}

	@Override
	public PageResponse<DevicePageVO> getPageDeviceList(DeviceInfoCmd deviceInfoCmd) {
		return deviceQryCmdExe.execute(deviceInfoCmd);
	}



    @Override
	public SingleResponse<SummaryDTO> statistics(DeviceInfoCmd deviceInfoCmd) {
		return deviceSummaryCmdExe.execute(deviceInfoCmd);
	}

	@Override
	public SingleResponse<Long> modifyStatus(Long id) {
		return deviceAddCmdExe.execute(id);
	}

	@Override
	public Response update(DeviceUpdateCmd deviceUpdateCmd) {
		return deviceUpdateCmdExe.execute(deviceUpdateCmd);
	}

	@Override
	public Response operateDoor(DeviceOperateDoorCmd deviceOperateDoorCmd) {
		return deviceOperateDoorCmdExe.execute(deviceOperateDoorCmd);
	}

	@Override
	public void deleteDeviceById(Long deviceId) {
		deviceDelCmdExe.execute(deviceId);
	}

	/**
	 * 设置门禁开放 结束时间段
	 *
	 * @param deviceUpdateCmd
	 * @return
	 */
	@Override
	public Response curfewTime(DeviceCurfewTimeCmd deviceUpdateCmd) throws ParseException {
		return deviceCurfewTimeCmdExe.execute(deviceUpdateCmd);
	}

	@Override
	public Response curfewOpenOrClose(DeviceCurfewOpenOrCloseCmd deviceCurfewOpenOrCloseCmd) {
		return deviceCurfewOpenOrCloseCmdExe.execute(deviceCurfewOpenOrCloseCmd);
	}


}
